import { createBrowserRouter } from "react-router-dom";
import { AuthRouter } from "@/components/AuthRouter";
import { lazy } from "react";
import { Suspense } from "react";

// 页面导入
import Layout from "@/pages/Layout";
import Login from "@/pages/Login";
import Index from "@/pages/Index";
import Cart from "@/pages/cart";
import Article from "@/pages/Article";

// 页面懒加载
const Home = lazy(() => import("@/pages/Home"));
const ArticleManagement = lazy(() => import("@/pages/ArticleManagement"));
const ArticleRelease = lazy(() => import("@/pages/ArticleRelease"));

const router = createBrowserRouter([
    {
        path: "/",
        element: <AuthRouter><Index /></AuthRouter>,
        children: [
            {
                path: "",
                element: <Cart />
            },
            {
                path: "article",
                element: <Article />
            }
        ]
    },
    {
        path: "/admin",
        element: <AuthRouter><Layout /></AuthRouter>,
        children: [
           {
               path: "",
               element: <Suspense fallback = {'加载中...'}><Home/></Suspense>
           },
           {
               path: "article-management",
               element: <Suspense fallback = {'加载中...'}><ArticleManagement/></Suspense>
           },
           {
               path: "article-release/",
               element: <Suspense fallback = {'加载中...'}><ArticleRelease/></Suspense>
           }
        ]
    },
    {
        path: "/login",
        element: <Login />
    }
])

export default router;